home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / GRAPH.SWG / 0017_PNG.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-04  |  48KB  |  1,059 lines

  1. --------I-PNG-M-----------------------------
  2.  
  3. "excerpted from the PNG (Portable Network Graphics) specification, tenth
  4. draft."
  5.  
  6. The PNG format (pronounced PiNG) was the replacement the Internet found,
  7. after  the GIF format/CompuServe/LZW compression-patent  stuff. PNG is a
  8. lossless  image-  compression  format,  which  allows  a  large range of
  9. applications.  The  PNG  format  is in  the  public  domain,  the latest
  10. versions  of the standard and related information can always be found at
  11. the  PNG FTP archive site, ftp.uu.net:/graphics/png/. The maintainers of
  12. the    PNG    specification    can   be    contacted    by   e-mail   at
  13. png-info@uunet.uu.net.
  14.  
  15. The  PNG format uses Motorola byte order, scanlines always begin on byte
  16. boundaries. When pixels are less than 8 bits deep, if the scanline width
  17. is  not  evenly  divisible  by the number  of  pixels  per byte then the
  18. low-order  bits  in  the  last byte  of  each  scanline  are wasted. The
  19. contents  of  the  padding  bits added to  fill  out  the last byte of a
  20. scanline are unspecified.
  21.  
  22. An additional "filter" byte is added to the beginning of every scanline,
  23. as  described in detail below. The filter byte is not considered part of
  24. the  image  data,  but  it is included  in  the  data stream sent to the
  25. compression step.
  26.  
  27. PNG  allows  the image data to be  filtered before it is compressed. The
  28. purpose  of filtering is to improve the compressibility of the data. The
  29. filter step itself does not reduce the size of the data. All PNG filters
  30. are strictly lossless.
  31.  
  32. PNG  defines several different filter algorithms, including "none" which
  33. indicates  no  filtering.  The filter  algorithm  is  specified for each
  34. scanline  by a filter type byte  which precedes the filtered scanline in
  35. the  precompression  data  stream.  An  intelligent  encoder  may switch
  36. filters  from  one scanline to the  next.  The method for choosing which
  37. filter to employ is up to the encoder.
  38.  
  39. A  PNG  image  can be stored  in  interlaced  order to allow progressive
  40. display.  The  purpose of this feature is  to  allow images to "fade in"
  41. when  they are being displayed  on-the-fly. Interlacing slightly expands
  42. the  file  size on average, but it  gives  the user a meaningful display
  43. much  more  rapidly. Note that decoders are  required to be able to read
  44. interlaced  images,  whether  or not  they  actually perform progressive
  45. display.
  46.  
  47. With  interlace  type  0, pixels are  stored  sequentially  from left to
  48. right, and scanlines sequentially from top to bottom (no interlacing).
  49.  
  50. Interlace  type  1, known as Adam7  after  its author, Adam M. Costello,
  51. consists  of seven distinct passes over the image. Each pass transmits a
  52. subset  of  the  pixels in the image.  The  pass  in which each pixel is
  53. transmitted  is defined by replicating the following 8-by-8 pattern over
  54. the entire image, starting at the upper left corner:
  55.  
  56. 1 6 4 6 2 6 4 6
  57. 7 7 7 7 7 7 7 7
  58. 5 6 5 6 5 6 5 6
  59. 7 7 7 7 7 7 7 7
  60. 3 6 4 6 3 6 4 6
  61. 7 7 7 7 7 7 7 7
  62. 5 6 5 6 5 6 5 6
  63. 7 7 7 7 7 7 7 7
  64.  
  65. Within  each  pass,  the selected pixels  are  transmitted left to right
  66. within  a  scanline,  and selected  scanlines  sequentially  from top to
  67. bottom. For example, pass 2 contains pixels 4, 12, 20, etc. of scanlines
  68. 0,  8, 16, etc. (numbering from 0,0  at the upper left corner). The last
  69. pass contains the entirety of scanlines 1, 3, 5, etc.
  70.  
  71. The data within each pass is laid out as though it were a complete image
  72. of the appropriate dimensions. For example, if the complete image is 8x8
  73. pixels,  then  pass  3  will contain  a  single  scanline containing two
  74. pixels.  When  pixels are less than 8  bits  deep, each such scanline is
  75. padded to fill an integral number of bytes (see Image layout). Filtering
  76. is  done on this reduced image in the  usual way, and a filter type byte
  77. is  transmitted  before each of  its  scanlines (see Filter Algorithms).
  78. Notice  that the transmission order is defined so that all the scanlines
  79. transmitted  in  a  pass will have the  same  number  of pixels; this is
  80. necessary for proper application of some of the filters.
  81.  
  82. Caution:  If  the image contains fewer  than  five columns or fewer than
  83. five  rows,  some  passes will be  entirely  empty.  Encoder and decoder
  84. authors  must  be careful to handle  this case correctly. In particular,
  85. filter  bytes  are  only associated  with  nonempty scanlines; no filter
  86. bytes are present in an empty pass.
  87.  
  88. A  PNG file consists of a PNG  signature followed by a series of chunks.
  89. This  chapter defines the signature and  the basic properties of chunks.
  90. Individual chunk types are discussed in the next chapter.
  91.  
  92.  
  93. PNG Header
  94. OFFSET              Count TYPE   Description
  95. 0000h                   8 char   ID=89h,'PNG',13,10,26,10
  96.  
  97. Chunk layout
  98. OFFSET              Count TYPE   Description
  99. 0000h                   1 dword  Number of data bytes after this header.
  100. 0004h                   4 char   Chunk type.
  101.                                  A 4-byte chunk type code. For convenience in
  102.                                  description and in examining PNG files, type
  103.                                  codes are restricted to consist of uppercase
  104.                                  and lowercase ASCII letters (A-Z, a-z).
  105.                                  However, encoders and decoders should treat the
  106.                                  codes as fixed binary values, not character
  107.                                  strings. For example, it would not be correct
  108.                                  to represent the type code IDAT by the EBCDIC
  109.                                  equivalents of those letters.
  110. ????h                   ? byte   Data
  111. ????h                   1 dword  CRC calculated on the preceding bytes in that
  112.                                  chunk, including the chunk type code and chunk
  113.                                  data fields, but not including the length
  114.                                  field. The CRC is always present, even for
  115.                                  empty chunks such as IEND. The CRC algorithm
  116.                                  is specified below.
  117.  
  118. Chunk naming conventions
  119. ========================
  120.  
  121. Chunk type codes are assigned in such a way that a decoder can determine
  122. some  properties of a chunk even if it does not recognize the type code.
  123. These  rules  are intended to allow  safe, flexible extension of the PNG
  124. format, by allowing a decoder to decide what to do when it encounters an
  125. unknown  chunk.  The  naming rules are  not  normally of interest when a
  126. decoder does recognize the chunk's type.
  127.  
  128. Four  bits  of the type code, namely bit  5 (value 32) of each byte, are
  129. used to convey chunk properties. This choice means that a human can read
  130. off the assigned properties according to whether each letter of the type
  131. code  is  uppercase  (bit 5 is 0)  or  lowercase  (bit 5 is 1). However,
  132. decoders  should test the properties of  an unknown chunk by numerically
  133. testing  the specified bits; testing whether a character is uppercase or
  134. lowercase  is inefficient, and even  incorrect if a locale-specific case
  135. definition is used.
  136.  
  137. It  is also worth noting that the  property bits are an inherent part of
  138. the  chunk name, and hence are fixed  for any chunk type. Thus, TEXT and
  139. Text   are  completely  unrelated  chunk  type  codes.  Decoders  should
  140. recognize  codes by simple four-byte literal comparison; it is incorrect
  141. to perform case conversion on type codes.
  142.  
  143. The semantics of the property bits are:
  144.  
  145. First Byte: 0 (uppercase) = critical, 1 (lowercase) = ancillary
  146.    Chunks which are not strictly necessary in order to meaningfully
  147.    display the contents of the file are known as "ancillary" chunks.
  148.    Decoders encountering an unknown chunk in which the
  149.    ancillary bit is 1 may safely ignore the chunk and proceed to
  150.    display the image. The time chunk (tIME) is an example of an
  151.    ancillary chunk.
  152.  
  153.    Chunks which are critical to the successful display of the file's
  154.    contents are called "critical" chunks. Decoders encountering an
  155.    unknown chunk in which the ancillary bit is 0 must indicate to
  156.    the user that the image contains information they cannot safely
  157.    interpret. The image header chunk (IHDR) is an example of a
  158.    critical chunk.
  159.  
  160. Second Byte: 0 (uppercase) = public, 1 (lowercase) = private
  161.    If the chunk is public (part of this specification or a later edition
  162.    of this specification), its second letter is uppercase. If your
  163.    application requires proprietary chunks, and you have no interest
  164.    in seeing the software of other vendors recognize them, use a
  165.    lowercase second letter in the chunk name. Such names will
  166.    never be assigned in the official specification. Note that there is
  167.    no need for software to test this property bit; it simply ensures
  168.    that private and public chunk names will not conflict.
  169.  
  170. Third Byte: reserved, must be 0 (uppercase) always
  171.    The significance of the case of the third letter of the chunk name
  172.    is reserved for possible future expansion. At the present time all
  173.    chunk names must have uppercase third letters.
  174.  
  175. Fourth Byte: 0 (uppercase) = unsafe to copy, 1 (lowercase) = safe to copy
  176. This  property bit is not of interest to pure decoders, but it is needed
  177. by PNG editors (programs that modify a PNG file).
  178.  
  179. If  a  chunk's  safe-to-copy  bit is 1,  the  chunk  may  be copied to a
  180. modified PNG file whether or not the software recognizes the chunk type,
  181. and regardless of the extent of the file modifications.
  182.  
  183. If  a chunk's safe-to-copy bit is 0, it indicates that the chunk depends
  184. on  the  image  data. If the program  has  made  any changes to critical
  185. chunks,  including  addition, modification,  deletion,  or reordering of
  186. critical  chunks, then unrecognized unsafe chunks  must not be copied to
  187. the  output  PNG  file. (Of course,  if  the  program does recognize the
  188. chunk, it may choose to output an appropriately modified version.)
  189.  
  190. A PNG editor is always allowed to copy all unrecognized chunks if it has
  191. only  added, deleted, or modified ancillary chunks. This implies that it
  192. is  not  permissible  to  make ancillary  chunks  that  depend  on other
  193. ancillary chunks.
  194.  
  195. PNG  editors that do not recognize a critical chunk must report an error
  196. and refuse to process that PNG file at all. The safe/unsafe mechanism is
  197. intended for use with ancillary chunks. The safe-to-copy bit will always
  198. be 0 for critical chunks.
  199.  
  200. For  example,  the hypothetical chunk type  name "bLOb" has the property
  201. bits:
  202.  
  203.     bLOb  <-- 32 bit Chunk Name represented in ASCII form
  204.     ||||
  205.     |||'- Safe to copy bit is 1 (lower case letter; bit 5 of byte is 1)
  206.     ||'-- Reserved bit is 0     (upper case letter; bit 5 of byte is 0)
  207.     |'--- Private bit is 0      (upper case letter; bit 5 of byte is 0)
  208.     '---- Ancillary bit is 1    (lower case letter; bit 5 of byte is 1)
  209.  
  210. Therefore,  this  name  represents  an  ancillary,  public, safe-to-copy
  211. chunk.
  212.  
  213. See Rationale: Chunk naming conventions.
  214.  
  215. CRC algorithm
  216. =============
  217.  
  218. Chunk  CRCs are calculated using standard  CRC methods with pre and post
  219. conditioning. The CRC polynomial employed is as follows:
  220.  
  221. x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
  222.  
  223. The  32-bit  CRC register is initialized to  all  1's, and then the data
  224. from  each  byte is processed from the  least significant bit (1) to the
  225. most  significant bit (128). After all the data bytes are processed, the
  226. CRC  register is inverted (its ones  complement is taken). This value is
  227. transmitted  (stored  in  the  file)  MSB  first.  For  the  purpose  of
  228. separating  into  bytes and ordering, the  least  significant bit of the
  229. 32-bit CRC is defined to be the coefficient of the x^31 term.
  230.  
  231. Practical calculation of the CRC always employs a precalculated table to
  232. greatly accelerate the computation. See Appendix: Sample CRC Code.
  233.  
  234. 4. Chunk Specifications
  235. =======================
  236.  
  237. This chapter defines the standard types of PNG chunks.
  238.  
  239. Critical Chunks
  240. ===============
  241.  
  242. All implementations must understand and successfully render the standard
  243. critical  chunks.  A valid PNG image must  contain an IHDR chunk, one or
  244. more IDAT chunks, and an IEND chunk.
  245.  
  246. IHDR Image Header This chunk must appear FIRST. Its contents are:
  247.  
  248.    Width:            4 bytes
  249.    Height:           4 bytes
  250.    Bit depth:        1 byte
  251.    Color type:       1 byte
  252.    Compression type: 1 byte
  253.    Filter type:      1 byte
  254.    Interlace type:   1 byte
  255.  
  256. Width  and  height give the image  dimensions in pixels. They are 4-byte
  257. integers.  Zero is an invalid value. The maximum for each is (2^31)-1 in
  258. order  to  accommodate  languages which  have  difficulty  with unsigned
  259. 4-byte values.
  260.  
  261. Bit  depth is a single-byte integer giving  the number of bits per pixel
  262. (for palette images) or per sample (for grayscale and truecolor images).
  263. Valid values are 1, 2, 4, 8, and 16, although not all values are allowed
  264. for all color types.
  265.  
  266. Color type is a single-byte integer that describes the interpretation of
  267. the  image  data.  Color  type values  represent  sums  of the following
  268. values: 1 (palette used), 2 (color used), and 4 (full alpha used). Valid
  269. values are 0, 2, 3, 4, and 6.
  270.  
  271. Bit  depth restrictions for each color type are imposed both to simplify
  272. implementations  and  to  prohibit  certain  combinations  that  do  not
  273. compress  well in practice. Decoders must support all legal combinations
  274. of  bit  depth  and color type. (Note  that  bit depths of 16 are easily
  275. supported  on  8-bit display hardware  by dropping the least significant
  276. byte.) The allowed combinations are:
  277.  
  278.    Color    Allowed    Interpretation
  279.    Type    Bit Depths
  280.  
  281.    0       1,2,4,8,16  Each pixel value is a grayscale level.
  282.  
  283.    2       8,16        Each pixel value is an R,G,B series.
  284.  
  285.    3       1,2,4,8     Each pixel value is a palette index;
  286.                        a PLTE chunk must appear.
  287.  
  288.    4       8,16        Each pixel value is a grayscale level,
  289.                        followed by an alpha channel level.
  290.  
  291.    6       8,16        Each pixel value is an R,G,B series,
  292.                        followed by an alpha channel level.
  293.  
  294. Compression type is a single-byte integer that indicates the method used
  295. to  compress  the  image  data.  At  present,  only  compression  type 0
  296. (deflate/inflate  compression with a 32K sliding window) is defined. All
  297. standard PNG images must be compressed with this scheme. The compression
  298. type  code  is  provided for  possible  future  expansion or proprietary
  299. variants.  Decoders must check this byte and report an error if it holds
  300. an unrecognized code. See Deflate/Inflate Compression for details.
  301.  
  302. Filter  type  is a single-byte  integer that indicates the preprocessing
  303. method  applied  to the image data  before compression. At present, only
  304. filter  type  0  (adaptive filtering with  five  basic  filter types) is
  305. defined.  As  with the compression type  code,  decoders must check this
  306. byte  and  report an error if it  holds an unrecognized code. See Filter
  307. Algorithms for details.
  308.  
  309. Interlace  type is a single-byte integer that indicates the transmission
  310. order  of  the  pixel  data. Two  values  are  currently  defined: 0 (no
  311. interlace)  or  1  (Adam7  interlace).  See  Interlaced  data  order for
  312. details.
  313.  
  314. PLTE Palette
  315. This  chunk's  contents  are  from  1  to  256  palette  entries, each a
  316. three-byte series of the form:
  317.  
  318.    red:   1 byte (0 = black, 255 = red)
  319.    green: 1 byte (0 = black, 255 = green)
  320.    blue:  1 byte (0 = black, 255 = blue)
  321.  
  322. The  number  of  entries is determined  from  the  chunk length. A chunk
  323. length not divisible by 3 is an error.
  324.  
  325. This  chunk must appear for color type 3, and may appear for color types
  326. 2  and  6.  If this chunk does  appear,  it  must precede the first IDAT
  327. chunk. There cannot be more than one PLTE chunk.
  328.  
  329. For  color type 3 (palette data), the  PLTE chunk is required. The first
  330. entry  in PLTE is referenced by pixel value 0, the second by pixel value
  331. 1, etc. The number of palette entries must not exceed the range that can
  332. be  represented by the bit depth (for example,  2^4 = 16 for a bit depth
  333. of  4). It is permissible to have fewer entries than the bit depth would
  334. allow.  In  that case, any out-of-range  pixel  value found in the image
  335. data is an error.
  336.  
  337. For  color  types  2 and 6 (truecolor),  the  PLTE chunk is optional. If
  338. present,  it provides a recommended set of from 1 to 256 colors to which
  339. the  truecolor  image  may  be quantized  if  the  viewer cannot display
  340. truecolor  directly.  If PLTE is not  present, such a viewer must select
  341. colors  on its own, but it is often  preferable for this to be done once
  342. by the encoder.
  343.  
  344. Note  that the palette uses 8 bits  (1 byte) per value regardless of the
  345. image bit depth specification. In particular, the palette is 8 bits deep
  346. even when it is a suggested quantization of a 16-bit truecolor image.
  347.  
  348. IDAT Image Data
  349. This  chunk  contains the actual image  data. To create this data, begin
  350. with  image  scanlines represented as  described under Image layout; the
  351. layout  and  total size of this raw  data are determinable from the IHDR
  352. fields.  Then  filter the image data  according  to the filtering method
  353. specified  by the IHDR chunk. (Note that  with filter method 0, the only
  354. one  currently  defined, this implies prepending  a  filter type byte to
  355. each   scanline.)   Finally,  compress  the   filtered  data  using  the
  356. compression  method specified by the IHDR chunk. The IDAT chunk contains
  357. the  output  datastream of the compression  algorithm. To read the image
  358. data, reverse this process.
  359.  
  360. There may be multiple IDAT chunks; if so, they must appear consecutively
  361. with  no other intervening chunks. The compressed datastream is then the
  362. concatenation  of  the contents of all  the IDAT chunks. The encoder may
  363. divide  the  compressed  data  stream into  IDAT  chunks  as  it wishes.
  364. (Multiple  IDAT chunks are allowed so that  encoders can work in a fixed
  365. amount  of  memory;  typically  the chunk  size  will  correspond to the
  366. encoder's  buffer  size.) It is important  to  emphasize that IDAT chunk
  367. boundaries  have no semantic significance and can appear at any point in
  368. the  compressed datastream. A PNG file in which each IDAT chunk contains
  369. only  one data byte is legal,  though remarkably wasteful of space. (For
  370. that  matter,  zero-length  IDAT  chunks  are  legal,  though  even more
  371. wasteful.)
  372.  
  373. See Filter Algorithms and Deflate/Inflate Compression for details.
  374.  
  375. IEND Image Trailer
  376. This  chunk  must appear LAST. It marks  the end of the PNG data stream.
  377. The chunk's data field is empty.
  378.  
  379. Ancillary Chunks
  380. ================
  381.  
  382. All  ancillary chunks are optional, in  the sense that encoders need not
  383. write   them  and  decoders  may  ignore  them.  However,  encoders  are
  384. encouraged  to write the standard  ancillary chunks when the information
  385. is available, and decoders are encouraged to interpret these chunks when
  386. appropriate and feasible.
  387.  
  388. The  standard ancillary chunks are listed in alphabetical order. This is
  389. not necessarily the order in which they would appear in a file.
  390.  
  391. bKGD Background Color
  392. This  chunk specifies a default background color against which the image
  393. may be presented. Note that viewers are not bound to honor this chunk; a
  394. viewer may choose to use a different background color.
  395.  
  396.    For color type 3 (palette), the bKGD chunk contains:
  397.  
  398.    palette index: 1 byte
  399.  
  400. The value is the palette index of the color to be used as background.
  401.  
  402. For  color  types  0  and 4  (grayscale,  with  or  without alpha), bKGD
  403. contains:
  404.  
  405.    gray:  2 bytes, range 0 .. (2^bitdepth) - 1
  406.  
  407. (For  consistency, 2 bytes are used  regardless of the image bit depth.)
  408. The value is the gray level to be used as background.
  409.  
  410. For color types 2 and 6 (RGB, with or without alpha), bKGD contains:
  411.  
  412.    red:   2 bytes, range 0 .. (2^bitdepth) - 1
  413.    green: 2 bytes, range 0 .. (2^bitdepth) - 1
  414.    blue:  2 bytes, range 0 .. (2^bitdepth) - 1
  415.  
  416. (For  consistency,  2 bytes per sample  are used regardless of the image
  417. bit depth.) This is the RGB color to be used as background.
  418.  
  419. When present, the bKGD chunk must precede the first IDAT chunk, and must
  420. follow the PLTE chunk, if any.
  421.  
  422.    See Recommendations for Decoders: Background color.
  423.  
  424. cHRM Primary Chromaticities and White Point
  425. Applications that need precise specification of colors in a PNG file may
  426. use this chunk to specify the chromaticities of the red, green, and blue
  427. primaries  used  in  the image, and  the  referenced  white point. These
  428. values  are  based on the 1931  CIE  (International Color Committee) XYZ
  429. color  space. Only the chromaticities (x and y) are specified. The chunk
  430. layout is:
  431.  
  432.    White Point x: 4 bytes
  433.    White Point y: 4 bytes
  434.    Red x:         4 bytes
  435.    Red y:         4 bytes
  436.    Green x:       4 bytes
  437.    Green y:       4 bytes
  438.    Blue x:        4 bytes
  439.    Blue y:        4 bytes
  440.  
  441. Each  value is encoded as a  4-byte unsigned integer, representing the x
  442. or y value times 100000.
  443.  
  444. If  the cHRM chunk appears, it must precede the first IDAT chunk, and it
  445. must also precede the PLTE chunk if present.
  446.  
  447. gAMA Gamma Correction
  448. The  gamma  correction  chunk  specifies the  gamma  of  the  camera (or
  449. simulated  camera)  that produced the image,  and  thus the gamma of the
  450. image with respect to the original scene. Note that this is not the same
  451. as  the  gamma  of  the display  device  that  will  reproduce the image
  452. correctly.
  453.  
  454.    The chunk's contents are:
  455.  
  456.    Image gamma value: 4 bytes
  457.  
  458. A value of 100000 represents a gamma of 1.0, a value of 45000 a gamma of
  459. 0.45,  and so on (divide by 100000.0). Values around 1.0 and around 0.45
  460. are common in practice.
  461.  
  462. If  the  encoder  does not know the  gamma  value, it should not write a
  463. gamma  chunk;  the  absence  of a  gamma  chunk  indicates  the gamma is
  464. unknown.
  465.  
  466. If  the gAMA chunk appears, it must precede the first IDAT chunk, and it
  467. must also precede the PLTE chunk if present.
  468.  
  469. See  Gamma  correction,  Recommendations  for  Encoders:  Encoder  gamma
  470. handling, and Recommendations for Decoders: Decoder gamma handling.
  471.  
  472. hIST Image Histogram
  473. The  histogram chunk gives the approximate usage frequency of each color
  474. in  the color palette. A histogram chunk  may appear only when a palette
  475. chunk appears. If a viewer is unable to provide all the colors listed in
  476. the  palette, the histogram may help it decide how to choose a subset of
  477. the colors for display.
  478.  
  479. This chunk's contents are a series of 2-byte (16 bit) unsigned integers.
  480. There  must be exactly one entry for  each entry in the PLTE chunk. Each
  481. entry  is proportional to the fraction of  pixels in the image that have
  482. that palette index; the exact scale factor is chosen by the encoder.
  483.  
  484. Histogram  entries are approximate, with the exception that a zero entry
  485. specifies that the corresponding palette entry is not used at all in the
  486. image. It is required that a histogram entry be nonzero if there are any
  487. pixels of that color.
  488.  
  489. When  the palette is a suggested  quantization of a truecolor image, the
  490. histogram  is necessarily approximate, since a decoder may map pixels to
  491. palette  entries  differently than the  encoder  did. In this situation,
  492. zero entries should not appear.
  493.  
  494. The  hIST  chunk,  if it appears, must  follow  the PLTE chunk, and must
  495. precede the first IDAT chunk.
  496.  
  497. See  Rationale:  Palette histograms,  and  Recommendations for Decoders:
  498. Palette histogram usage.
  499.  
  500. pHYs Physical Pixel Dimensions
  501. This  chunk specifies the intended resolution  for display of the image.
  502. The chunk's contents are:
  503.  
  504.    4 bytes: pixels per unit, X axis (unsigned integer)
  505.    4 bytes: pixels per unit, Y axis (unsigned integer)
  506.    1 byte: unit specifier
  507.  
  508.    The following values are legal for the unit specifier:
  509.  
  510.    0: unit is unknown (pHYs defines pixel aspect ratio only)
  511.    1: unit is the meter
  512.  
  513.    Conversion note: one inch is equal to exactly 0.0254 meters.
  514.  
  515. If this ancillary chunk is not present, pixels are assumed to be square,
  516. and the physical size of each pixel is unknown.
  517.  
  518.    If present, this chunk must precede the first IDAT chunk.
  519.  
  520.    See Recommendations for Decoders: Pixel dimensions.
  521.  
  522. sBIT Significant Bits
  523. To  simplify decoders, PNG specifies that  only certain bit depth values
  524. be  used, and further specifies that pixel  values must be scaled to the
  525. full range of possible values at that bit depth. However, the sBIT chunk
  526. is  provided in order to store  the original number of significant bits,
  527. since this information may be of use to some decoders. We recommend that
  528. an  encoder  emit  an  sBIT chunk if  it  has  converted the data from a
  529. different bit depth.
  530.  
  531. For  color  type 0 (grayscale), the  sBIT  chunk contains a single byte,
  532. indicating the number of bits which were significant in the source data.
  533.  
  534. For  color type 2 (RGB truecolor),  the sBIT chunk contains three bytes,
  535. indicating  the number of bits which were significant in the source data
  536. for the red, green, and blue channels, respectively.
  537.  
  538. For  color type 3 (palette color),  the sBIT chunk contains three bytes,
  539. indicating  the number of bits which were significant in the source data
  540. for  the  red,  green,  and  blue  components  of  the  palette entries,
  541. respectively.
  542.  
  543. For color type 4 (grayscale with alpha channel), the sBIT chunk contains
  544. two  bytes, indicating the number of  bits which were significant in the
  545. source grayscale data and the source alpha channel data, respectively.
  546.  
  547. For  color  type  6 (RGB truecolor  with  alpha channel), the sBIT chunk
  548. contains   four  bytes,  indicating  the   number  of  bits  which  were
  549. significant  in  the  source  data for  the  red,  green, blue and alpha
  550. channels, respectively.
  551.  
  552. Note  that sBIT does not have any implications for the interpretation of
  553. the  stored image: the bit depth indicated by IHDR is the correct depth.
  554. sBIT is only an indication of the history of the image. However, an sBIT
  555. chunk  showing  a bit depth less than  the IHDR bit depth does mean that
  556. not  all  possible color values occur in  the image; this fact may be of
  557. use to some decoders.
  558.  
  559. If  the sBIT chunk appears, it must precede the first IDAT chunk, and it
  560. must also precede the PLTE chunk if present.
  561.  
  562. tEXt Textual Data
  563. Any textual information that the encoder wishes to record with the image
  564. is  stored in tEXt chunks. Each tEXt chunk contains a keyword and a text
  565. string, in the format:
  566.  
  567.    Keyword:        n bytes (character string)
  568.    Null separator: 1 byte
  569.    Text:           n bytes (character string)
  570.  
  571. The  keyword  and  text  string  are  separated  by  a  zero  byte (null
  572. character).  Neither the keyword nor the  text string may contain a null
  573. character.  Note that the text string is not null-terminated (the length
  574. of  the  chunk  is  sufficient information  to  locate  the ending). The
  575. keyword must be at least one character and less than 80 characters long.
  576. The  text string may be of any length  from zero bytes up to the maximum
  577. permissible chunk size.
  578.  
  579. Any  number  of tEXt chunks may appear,  and more than one with the same
  580. keyword is permissible.
  581.  
  582. The  keyword  indicates the type of  information represented by the text
  583. string.  The following keywords are predefined  and should be used where
  584. appropriate:
  585.  
  586.    Title            Short (one line) title or caption for image
  587.    Author           Name of image's creator
  588.    Copyright        Copyright notice
  589.    Description      Description of image (possibly long)
  590.    Software         Software used to create the image
  591.    Disclaimer       Legal disclaimer
  592.    Warning          Warning of nature of content
  593.    Source           Device used to create the image
  594.    Comment          Miscellaneous comment; conversion from GIF comment
  595.  
  596. Other  keywords, containing any sequence  of printable characters in the
  597. character  set, may be invented for  other purposes. Keywords of general
  598. interest   may   be   registered  with   the   maintainers  of  the  PNG
  599. specification.
  600.  
  601. Keywords must be spelled exactly as registered, so that decoders may use
  602. simple  literal  comparisons  when looking  for  particular keywords. In
  603. particular, keywords are considered case-sensitive.
  604.  
  605. Both  keyword  and  text  are interpreted  according  to  the ISO 8859-1
  606. (Latin-1)   character  set.  Newlines  in  the  text  string  should  be
  607. represented  by  a single linefeed character  (decimal 10); use of other
  608. ASCII control characters is discouraged.
  609.  
  610. See   Recommendations   for   Encoders:   Text   chunk   processing  and
  611. Recommendations for Decoders: Text chunk processing.
  612.  
  613. tIME Image Last-Modification Time
  614. This  chunk gives the time of the  last image modification (not the time
  615. of initial image creation). The chunk contents are:
  616.  
  617.    2 bytes: Year (complete; for example, 1995, not 95)
  618.    1 byte: Month (1-12)
  619.    1 byte: Day (1-31)
  620.    1 byte: Hour (0-23)
  621.    1 byte: Minute (0-59)
  622.    1 byte: Second (0-60)    (yes, 60, for leap seconds; not 61, a common error)
  623.  
  624. Universal  Time  (UTC, also called GMT)  should be specified rather than
  625. local time.
  626.  
  627. tRNS Transparency
  628. Transparency  is  an  alternative to  the  full  alpha channel. Although
  629. transparency  is  not as elegant as  the full alpha channel, it requires
  630. less storage space and is sufficient for many common cases.
  631.  
  632. For  color type 3 (palette), this chunk's contents are a series of alpha
  633. channel bytes, corresponding to entries in the PLTE chunk:
  634.  
  635.    Alpha for palette index 0:  1 byte
  636.    Alpha for palette index 1:  1 byte
  637.    etc.
  638.  
  639. Each entry indicates that pixels of that palette index should be treated
  640. as  having  the  specified  alpha  value.  Alpha  values  have  the same
  641. interpretation   as  in  an  8-bit  full   alpha  channel:  0  is  fully
  642. transparent,  255  is fully opaque, regardless  of  image bit depth. The
  643. tRNS  chunk may contain fewer alpha channel bytes than there are palette
  644. entries. In this case, the alpha channel value for all remaining palette
  645. entries  is  assumed  to be 255. In  the  common case where only palette
  646. index  0 need be made transparent, only a one-byte tRNS chunk is needed.
  647. The  tRNS  chunk  may  not contain  more  bytes  than  there are palette
  648. entries.
  649.  
  650. For  color  type  0 (grayscale), the  tRNS  chunk contains a single gray
  651. level value, stored in the format
  652.  
  653.    gray:  2 bytes, range 0 .. (2^bitdepth) - 1
  654.  
  655. (For  consistency, 2 bytes are used  regardless of the image bit depth.)
  656. Pixels  of  the  specified gray level  are  to be treated as transparent
  657. (equivalent  to  alpha value 0); all other  pixels  are to be treated as
  658. fully opaque (alpha value (2^bitdepth)-1).
  659.  
  660. For  color  type  2 (RGB), the tRNS  chunk  contains  a single RGB color
  661. value, stored in the format
  662.  
  663.    red:   2 bytes, range 0 .. (2^bitdepth) - 1
  664.    green: 2 bytes, range 0 .. (2^bitdepth) - 1
  665.    blue:  2 bytes, range 0 .. (2^bitdepth) - 1
  666.  
  667. (For  consistency,  2 bytes per sample  are used regardless of the image
  668. bit  depth.)  Pixels of the specified color  value  are to be treated as
  669. transparent  (equivalent  to alpha value 0);  all other pixels are to be
  670. treated as fully opaque (alpha value (2^bitdepth)-1).
  671.  
  672. tRNS  is prohibited for color types 4  and 6, since a full alpha channel
  673. is already present in those cases.
  674.  
  675. Note: when dealing with 16-bit grayscale or RGB data, it is important to
  676. compare  both bytes of the sample values to determine whether a pixel is
  677. transparent.  Although  decoders  may  drop  the  low-order  byte of the
  678. samples  for display, this must not occur  until after the data has been
  679. tested  for transparency. For example, if  the grayscale level 0x0001 is
  680. specified  to be transparent, it would  be incorrect to compare only the
  681. high-order byte and decide that 0x0002 is also transparent.
  682.  
  683. When present, the tRNS chunk must precede the first IDAT chunk, and must
  684. follow the PLTE chunk, if any.
  685.  
  686. zTXt Compressed Textual Data
  687. A  zTXt  chunk contains textual data,  just  as tEXt does; however, zTXt
  688. takes advantage of compression.
  689.  
  690. A  zTXt chunk begins with an  uncompressed Latin-1 keyword followed by a
  691. null  (0) character, just as in the  tEXt chunk. The next byte after the
  692. null  contains  a  compression type byte,  for  which the only presently
  693. legitimate    value   is   zero   (deflate/inflate   compression).   The
  694. compression-type  byte  is  followed by  a  compressed data stream which
  695. makes  up the remainder of the  chunk. Decompression of this data stream
  696. yields  Latin-1  text which is equivalent to  the  text stored in a tEXt
  697. chunk.
  698.  
  699. Any  number of zTXt and tEXt chunks may appear in the same file. See the
  700. preceding  definition of the tEXt chunk  for the predefined keywords and
  701. the exact format of the text.
  702.  
  703. See  Deflate/Inflate  Compression,  Recommendations  for  Encoders: Text
  704. chunk   processing,   and  Recommendations   for  Decoders:  Text  chunk
  705. processing.
  706.  
  707. Summary of Standard Chunks
  708. ==========================
  709.  
  710. This table summarizes some properties of the standard chunk types.
  711.  
  712. Critical chunks (must appear in this order, except PLTE is optional):
  713.  
  714.         Name  Multiple  Ordering constraints
  715.                 OK?
  716.  
  717.         IHDR    No      Must be first
  718.         PLTE    No      Before IDAT
  719.         IDAT    Yes     Multiple IDATs must be consecutive
  720.         IEND    No      Must be last
  721.  
  722. Ancillary chunks (need not appear in this order):
  723.  
  724.         Name  Multiple  Ordering constraints
  725.                 OK?
  726.  
  727.         cHRM    No      Before PLTE and IDAT
  728.         gAMA    No      Before PLTE and IDAT
  729.         sBIT    No      Before PLTE and IDAT
  730.         bKGD    No      After PLTE; before IDAT
  731.         hIST    No      After PLTE; before IDAT
  732.         tRNS    No      After PLTE; before IDAT
  733.         pHYs    No      Before IDAT
  734.         tIME    No      None
  735.         tEXt    Yes     None
  736.         zTXt    Yes     None
  737.  
  738. Standard keywords for tEXt and zTXt chunks:
  739.  
  740. Title            Short (one line) title or caption for image
  741. Author           Name of image's creator
  742. Copyright        Copyright notice
  743. Description      Description of image (possibly long)
  744. Software         Software used to create the image
  745. Disclaimer       Legal disclaimer
  746. Warning          Warning of nature of content
  747. Source           Device used to create the image
  748. Comment          Miscellaneous comment; conversion from GIF comment
  749.  
  750. Additional Chunk Types
  751. ======================
  752.  
  753. Additional  public  PNG  chunk types are  defined  in  the document "PNG
  754. Special-Purpose     Public    Chunks",    available    by    FTP    from
  755. ftp.uu.net:/graphics/png/         or         via         WWW        from
  756. http://sunsite.unc.edu/boutell/pngextensions.html.
  757.  
  758. 5. Deflate/Inflate Compression
  759. ==============================
  760.  
  761. PNG  compression  type 0 (the  only compression method presently defined
  762. for  PNG)  specifies  deflate/inflate  compression  with  a  32K window.
  763. Deflate  compression is an LZ77 derivative  used in zip, gzip, pkzip and
  764. related  programs.  Extensive  research  has  been  done  supporting its
  765. patent-free status. Portable C implementations are freely available.
  766.  
  767. Documentation  and  C code for deflate  are  available from the Info-Zip
  768. archives at ftp.uu.net:/pub/archiving/zip/.
  769.  
  770. Deflate-compressed  datastreams  within  PNG are  stored  in  the "zlib"
  771. format, which has the structure:
  772.  
  773. Compression method/flags code: 1 byte
  774. Additional flags/check bits:   1 byte
  775. Compressed data blocks:        n bytes
  776. Checksum:                      4 bytes
  777.  
  778. Further  details on this format may  be found in the zlib specification.
  779. At  this  writing,  the  zlib  specification  is  at  draft  3.1, and is
  780. available from ftp.uu.net:/pub/archiving/zip/doc/zlib-3.1.doc.
  781.  
  782. For  PNG compression type 0, the zlib compression method/flags code must
  783. specify method code 8 ("deflate" compression) and an LZ77 window size of
  784. not more than 32K.
  785.  
  786. The  checksum stored at the end of  the zlib datastream is calculated on
  787. the  uncompressed  data  represented by  the  datastream.  Note that the
  788. algorithm used is not the same as the CRC calculation used for PNG chunk
  789. checksums.  Verifying  the chunk CRCs  provides adequate confidence that
  790. the PNG file has been transmitted undamaged. The zlib checksum is useful
  791. mainly  as  a  crosscheck that the  deflate  and  inflate algorithms are
  792. implemented correctly.
  793.  
  794. In  a PNG file, the concatenation of the contents of all the IDAT chunks
  795. makes   up  a  zlib  datastream  as  specified  above.  This  datastream
  796. decompresses  to  filtered  image data  as  described  elsewhere in this
  797. document.
  798.  
  799. It is important to emphasize that the boundaries between IDAT chunks are
  800. arbitrary  and  may fall anywhere in  the  zlib datastream. There is not
  801. necessarily  any  correlation between IDAT  chunk boundaries and deflate
  802. block  boundaries or any other feature of the zlib data. For example, it
  803. is  entirely  possible  for the terminating  zlib  checksum  to be split
  804. across IDAT chunks.
  805.  
  806. PNG  also  uses  zlib datastreams in zTXt  chunks.  In a zTXt chunk, the
  807. remainder  of  the chunk following the  compression  type code byte is a
  808. zlib  datastream as specified above. This datastream decompresses to the
  809. user-readable  text  described by the  chunk's keyword. Unlike the image
  810. data,  such  datastreams  are not split  across  chunks; each zTXt chunk
  811. contains an independent zlib datastream.
  812.  
  813. 6. Filter Algorithms
  814. ====================
  815.  
  816. This  chapter  describes  the pixel  filtering  algorithms  which may be
  817. applied  in  advance of compression. The  purpose of these filters is to
  818. prepare the image data for optimum compression.
  819.  
  820. PNG  defines  five basic filtering  algorithms,  which are given numeric
  821. codes as follows:
  822.  
  823. Code    Name
  824. 0       None
  825. 1       Sub
  826. 2       Up
  827. 3       Average
  828. 4       Paeth
  829.  
  830. The    encoder   may   choose   which    algorithm   to   apply   on   a
  831. scanline-by-scanline  basis.  In the image  data sent to the compression
  832. step,  each  scanline is preceded by  a  filter type byte containing the
  833. numeric code of the filter algorithm used for that scanline.
  834.  
  835. Filtering  algorithms are applied to bytes, not to pixels, regardless of
  836. the  bit depth or color type of the image. The filtering algorithms work
  837. on  the byte sequence formed by a  scanline that has been represented as
  838. described under Image layout.
  839.  
  840. When  the  image  is interlaced, each  pass  of the interlace pattern is
  841. treated as an independent image for filtering purposes. The filters work
  842. on the byte sequences formed by the pixels actually transmitted during a
  843. pass,  and the "previous scanline" is  the one previously transmitted in
  844. the same pass, not the one adjacent in the complete image. Note that the
  845. subimage  transmitted  in any one pass  is always rectangular, but is of
  846. smaller  width  and/or height than the  complete image. Filtering is not
  847. applied when this subimage is empty.
  848.  
  849. For  all  filters,  the  bytes "to the  left  of"  the  first pixel in a
  850. scanline  must  be treated as being zero.  For filters that refer to the
  851. prior  scanline,  the  entire prior scanline  must  be  treated as being
  852. zeroes for the first scanline of an image (or of a pass of an interlaced
  853. image).
  854.  
  855. To  reverse  the  effect of a filter,  the  decoder must use the decoded
  856. values  of the prior pixel on the same line, the pixel immediately above
  857. the  current pixel on the prior line, and  the pixel just to the left of
  858. the  pixel  above.  This implies that  at  least one scanline's worth of
  859. image  data must be stored by the decoder at all times. Even though some
  860. filter types do not refer to the prior scanline, the decoder must always
  861. store  each scanline as it is decoded, since the next scanline might use
  862. a filter that refers to it.
  863.  
  864. PNG  imposes  no restriction on which filter  types may be applied to an
  865. image.  However,  the filters are not  equally effective on all types of
  866. data. See Recommendations for Encoders: Filter selection.
  867.  
  868. Filter type 0: None
  869. ===================
  870.  
  871. With the None filter, the scanline is transmitted unmodified; it is only
  872. necessary to insert a filter type byte before the data.
  873.  
  874. Filter type 1: Sub
  875. ==================
  876.  
  877. The  Sub filter transmits the difference between each byte and the value
  878. of the corresponding byte of the prior pixel.
  879.  
  880. To  compute the Sub filter, apply the  following formula to each byte of
  881. each scanline:
  882.  
  883.   Sub(x) = Raw(x) - Raw(x-bpp)
  884.  
  885. where  x  ranges  from  zero to  the  number  of bytes representing that
  886. scanline  minus  one,  Raw(x) refers to the  raw  data byte at that byte
  887. position  in the scanline, and bpp is defined as the number of bytes per
  888. complete pixel, rounding up to one. For example, for color type 2 with a
  889. bit  depth  of  16,  bpp is equal  to  6  (three channels, two bytes per
  890. channel);  for  color  type 0 with a bit  depth  of 2, bpp is equal to 1
  891. (rounding  up); for color type 4 with a bit depth of 16, bpp is equal to
  892. 4 (two-byte grayscale value, plus two-byte alpha channel).
  893.  
  894. Note this computation is done for each byte, regardless of bit depth. In
  895. a 16-bit image, MSBs are differenced from the preceding MSB and LSBs are
  896. differenced  from  the  preceding LSB, because  of  the  way that bpp is
  897. defined.
  898.  
  899. Unsigned  arithmetic  modulo  256 is used,  so  that both the inputs and
  900. outputs fit into bytes. The sequence of Sub values is transmitted as the
  901. filtered scanline.
  902.  
  903. For all x < 0, assume Raw(x) = 0.
  904.  
  905. To  reverse the effect of the Sub filter after decompression, output the
  906. following value:
  907.  
  908.   Sub(x) + Raw(x-bpp)
  909.  
  910. (computed mod 256), where Raw refers to the bytes already decoded.
  911.  
  912. Filter type 2: Up
  913. =================
  914.  
  915. The  Up  filter  is  just  like the  Sub  filter  except  that the pixel
  916. immediately  above  the current pixel, rather  than just to its left, is
  917. used as the predictor.
  918.  
  919. To  compute  the Up filter, apply the  following formula to each byte of
  920. each scanline:
  921.  
  922.   Up(x) = Raw(x) - Prior(x)
  923.  
  924. where  x  ranges  from  zero to  the  number  of bytes representing that
  925. scanline  minus  one,  Raw(x) refers to the  raw  data byte at that byte
  926. position in the scanline, and Prior(x) refers to the unfiltered bytes of
  927. the prior scanline.
  928.  
  929. Note  this  is  done for each  byte,  regardless  of bit depth. Unsigned
  930. arithmetic  modulo 256 is used, so that  both the inputs and outputs fit
  931. into  bytes.  The sequence of Up  values  is transmitted as the filtered
  932. scanline.
  933.  
  934. On the first scanline of an image (or of a pass of an interlaced image),
  935. assume Prior(x) = 0 for all x.
  936.  
  937. To  reverse the effect of the  Up filter after decompression, output the
  938. following value:
  939.  
  940.   Up(x) + Prior(x)
  941.  
  942. (computed mod 256), where Prior refers to the decoded bytes of the
  943. prior scanline.
  944.  
  945. Filter type 3: Average
  946. ======================
  947.  
  948. The  Average filter uses the average of the two neighboring pixels (left
  949. and above) to predict the value of a pixel.
  950.  
  951. To  compute the Average filter, apply the following formula to each byte
  952. of each scanline:
  953.  
  954.   Average(x) = Raw(x) - floor((Raw(x-bpp)+Prior(x))/2)
  955.  
  956. where  x  ranges  from  zero to  the  number  of bytes representing that
  957. scanline  minus  one,  Raw(x) refers to the  raw  data byte at that byte
  958. position in the scanline, Prior(x) refers to the unfiltered bytes of the
  959. prior scanline, and bpp is defined as for the Sub filter.
  960.  
  961. Note  this is done for each byte,  regardless of bit depth. The sequence
  962. of Average values is transmitted as the filtered scanline.
  963.  
  964. The  subtraction  of the predicted value from  the raw byte must be done
  965. modulo 256, so that both the inputs and outputs fit into bytes. However,
  966. the  sum  Raw(x-bpp)+Prior(x) must be  formed without overflow (using at
  967. least  nine-bit  arithmetic). floor() indicates  that  the result of the
  968. division  is  rounded to the next  lower integer if fractional; in other
  969. words, it is an integer division or right shift operation.
  970.  
  971. For  all x < 0, assume Raw(x) = 0. On the first scanline of an image (or
  972. of a pass of an interlaced image), assume Prior(x) = 0 for all x.
  973.  
  974. To  reverse the effect of the Average filter after decompression, output
  975. the following value:
  976.  
  977.   Average(x) + floor((Raw(x-bpp)+Prior(x))/2)
  978.  
  979. where  the result is computed mod  256, but the prediction is calculated
  980. in  the  same  way  as for encoding.  Raw  refers  to  the bytes already
  981. decoded, and Prior refers to the decoded bytes of the prior scanline.
  982.  
  983. Filter type 4: Paeth
  984. ====================
  985.  
  986. The  Paeth  filter  computes  a  simple  linear  function  of  the three
  987. neighboring  pixels (left, above, upper left), then chooses as predictor
  988. the  neighboring pixel closest to the  computed value. This technique is
  989. taken from Alan W. Paeth's article "Image File Compression Made Easy" in
  990. Graphics Gems II, James Arvo, editor, Academic Press, 1991.
  991.  
  992. To compute the Paeth filter, apply the following formula to each byte of
  993. each scanline:
  994.  
  995.   Paeth(x) = Raw(x) - PaethPredictor(Raw(x-bpp),Prior(x),Prior(x-bpp))
  996.  
  997. where  x  ranges  from  zero to  the  number  of bytes representing that
  998. scanline  minus  one,  Raw(x) refers to the  raw  data byte at that byte
  999. position in the scanline, Prior(x) refers to the unfiltered bytes of the
  1000. prior scanline, and bpp is defined as for the Sub filter.
  1001.  
  1002. Note  this  is  done for each  byte,  regardless  of bit depth. Unsigned
  1003. arithmetic  modulo 256 is used, so that  both the inputs and outputs fit
  1004. into  bytes. The sequence of Paeth values is transmitted as the filtered
  1005. scanline.
  1006.  
  1007. The PaethPredictor function is defined by the following pseudocode:
  1008.  
  1009.      function PaethPredictor (a, b, c)
  1010.      begin
  1011.           ; a = left, b = above, c = upper left
  1012.           p := a + b - c        ; initial estimate
  1013.           pa := abs(p - a)      ; distances to a, b, c
  1014.           pb := abs(p - b)
  1015.           pc := abs(p - c)
  1016.           ; return nearest of a,b,c,
  1017.           ; breaking ties in order a,b,c.
  1018.           if pa <= pb AND pa <= pc
  1019.           begin
  1020.                return a
  1021.           end
  1022.           if pb <= pc
  1023.           begin
  1024.                return b
  1025.           end
  1026.           return c
  1027.      end
  1028.  
  1029. The  calculations  within the PaethPredictor  function must be performed
  1030. exactly,  without overflow. Arithmetic modulo 256 is to be used only for
  1031. the  final step of subtracting the function result from the target pixel
  1032. value.
  1033.  
  1034. Note  that  the order in which ties are  broken is fixed and must not be
  1035. altered.  The tie break order is: pixel  to the left, pixel above, pixel
  1036. to  the  upper  left.  (This order  differs  from  that given in Paeth's
  1037. article.)
  1038.  
  1039. For all x < 0, assume Raw(x) = 0 and Prior(x) = 0. On the first scanline
  1040. of  an image (or of a pass of  an interlaced image), assume Prior(x) = 0
  1041. for all x.
  1042.  
  1043. To  reverse  the effect of the  Paeth filter after decompression, output
  1044. the following value:
  1045.  
  1046.   Paeth(x) + PaethPredictor(Raw(x-bpp),Prior(x),Prior(x-bpp))
  1047.  
  1048. (computed  mod 256), where Raw and Prior refer to bytes already decoded.
  1049. Exactly  the  same PaethPredictor function is  used  by both encoder and
  1050. decoder.
  1051.  
  1052. For more information, check out the above ftp sites.
  1053.  
  1054. EXTENSION:PNG
  1055. OCCURENCES:PC,UNIX,AMIGA
  1056. PROGRAMS:????
  1057. REFERENCE:The PNG Specification
  1058.  
  1059.